﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace MixedOperation
{
   public class Operation
    {
        public List<decimal> Value = new List<decimal>();

        public List<string> GetSum(int count, int operators, bool IsBrackets)
        {
            return Sum(count, operators, IsBrackets, out string value);
        }
        public List<string> Sum(int count, int operators,bool IsBrackets, out string value)
        {
            Random ran = new Random();
            char[] vs = { '+', '-', '*', '/' };
            value = null;
            string t = "";
            int FirstDigit;
            int SecondDigit;
            int ThirdDigit;
            List<string> Subject = new List<string>();
            char ranoperators;
            char ranoperatorss;
            for (int i = 0; i < count; i++)
            {
                ranoperators = vs[ran.Next(operators)];
                ranoperatorss = vs[ran.Next(operators)];
                FirstDigit = ran.Next(1, 10);
                SecondDigit = ran.Next(1, 10);
                ThirdDigit = ran.Next(1, 10);
                if (IsBrackets == true)
                {
                    t ="("+ FirstDigit + ranoperators.ToString() + SecondDigit+ ")"+ ranoperatorss.ToString() + ThirdDigit;
                }
                else
                {
                    t = FirstDigit + ranoperators.ToString() + SecondDigit + ranoperatorss.ToString() + ThirdDigit;

                }
                value = new DataTable().Compute(t, "").ToString();
                Subject.Add(t + "= ?");
                var LastTwo = Math.Round(decimal.Parse(value), 2);
                Value.Add(LastTwo);
            }
            return Subject;
        }
    }
}
